<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('notifications', function (Blueprint $table) {
            $table->id();
            $table->string('type'); // 通知类型：follow, comment, like, system, post_approved, post_rejected
            $table->morphs('notifiable'); // 通知接收者
            $table->text('data'); // JSON格式的通知数据
            $table->timestamp('read_at')->nullable(); // 阅读时间
            $table->timestamps();

            // 索引
            $table->index(['notifiable_type', 'notifiable_id']);
            $table->index('type');
            $table->index('read_at');
            $table->index('created_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('notifications');
    }
};